import React, { useEffect, useState, useRef } from 'react';
import TableDataBlock from '@/components/TableDataBlock';
import PopImgShow from '@/components/PopImgShow';
import { connect } from 'umi';
import { Space } from 'antd'
import { order_status, goodsType_status, workType_status,  } from '@/common/contact';
const UserScore = (props) => {
  const { dispatch, loading, list, organizationAuthAdminList, hideFlag: showHide } = props;
  const { id } = props
  const hideFetch = (hideFlag, o) => {
    dispatch({
      type: 'weCom/fakeSetScoreHideFlag',
      payload: {
        hideFlag: hideFlag,
        id: o
      },
      callback: (e, total) => {
        handleCallback()
      },
    });
  }
  const handleCallback = () => {
    childRef.current.fetchGetData();
  };
  const searchItems = [
    {
      label: '用户阶段',
      type: 'stage',
      name: 'stage',
    },
    {
      label: '状态',
      name: 'status',
      type: 'select',
      select: {
        0: '无效',
        1: '有效',
      },
    },
    {
      label: '积分类型',
      name: 'userType',
      type: 'select',
      select: {
        admin: '员工',
      },
    },
    {
      label: '负责人',
      name: 'organizationAdminId',
      type: 'select',
      select: organizationAuthAdminList,
      fieldNames: { label: 'username', value: 'id' },
    },


  ];
  const getColumns = [
    {
      title: '员工姓名',
      dataIndex: 'organizationAdminName',
    },
    {
      title: '用户阶段',
      dataIndex: 'stageInfo',
      render: (e = {}) => {
        const { stageName } = e
        return stageName
      }
    },
    {
      title: '员工得分',
      dataIndex: 'adminScore',
    },
    {
      title: '用户得分',
      dataIndex: 'userScore',
    },
    {
      title: '得分时间',
      dataIndex: 'createTime',
    },
    {
      title: '订单积分描述',
      dataIndex: 'scoreDesc',
    },
    {
      title: '当前负责人得分',
      dataIndex: 'nowAdminScore',
    },
    {
      title: '状态',
      dataIndex: 'status',
      render: (e) => {
        return {
          0: '无效',
          1: '有效'
        }[e]
      }
    },
    {
      type: 'handle',
      width: 200,
      show: showHide !== '0',
      dataIndex: 'id',
      render: (val, record) => [
        {
          title: '显示',
          visible: record.hideFlag === '1' && showHide !== '0',
          click: () => {
            const { hideFlag, id } = record
            hideFetch('0', id)
          },
        },
        {
          title: '隐藏',
          visible: record.hideFlag !== '1' && showHide !== '0',
          click: () => {
            const { hideFlag, id } = record
            hideFetch('1', id)
          },
        },
      ],
    },
  ].filter(val => {
    const { show = true } = val
    return show
  });
  const childRef = useRef();
  return (
    <TableDataBlock
      params={{ organizationUserId: id, hideFlag: showHide }}
      cRef={childRef}
      searchItems={searchItems}
      loading={loading}
      columns={getColumns}
      rowKey={(record) => `${record.id}`}
      dispatchType="user/fetchUserStageScore"
      {...list}
    ></TableDataBlock>
  );
};
export default connect(({ user, weCom, loading }) => ({
  list: user.userStageScoreList,
  organizationAuthAdminList: weCom.organizationAuthAdminListAll,
  loading: loading.effects['user/fetchUserStageScore'],
}))(UserScore);;
